home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Fitts / MenuView.m < prev    next >
Encoding:
Text File  |  1992-07-28  |  3.2 KB  |  154 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "MenuView.h"
  5. #import <dpsclient/wraps.h>
  6. #import <appkit/color.h>
  7. #import "MenuItems.h"
  8.  
  9.  
  10. @implementation MenuView : View
  11.  
  12.  
  13. - initFrame: (NXRect *) frameRect;
  14. {
  15.     [super initFrame:frameRect];
  16.     
  17.     return self;
  18. }
  19.  
  20.  
  21. - drawVerticalMenu
  22. {
  23.     int i;
  24.     float y;
  25.     float x_center;
  26.     float item_height, item_width, item_distance;
  27.     NXRect rect;
  28.     
  29.     /* converts item millimeters to PS coord values */
  30.     item_width = MM_CONVERT * option1;
  31.     item_height  = MM_CONVERT * option2;
  32.     item_distance = MM_CONVERT * option3;
  33.  
  34.     [self getFrame:&rect];   /* get view size */
  35.     x_center = (rect.size.width / 2.0) - (item_width / 2.0);
  36.     
  37.     y = rect.size.height/2.0 + (numItems *(item_distance+item_height)) / 2.0;
  38.     
  39.     for ( i = 0; i < numItems; i++, y -= (item_distance+item_height) )
  40.     {
  41.         if ( hitItem == i )
  42.         NXSetColor(selectedColour);
  43.     else
  44.         NXSetColor(unselectedColour);
  45.         
  46.     menu_rect(x_center, y, item_height, item_width);
  47.         PSgsave(); PSfill(); PSgrestore();
  48.         PSsetgray(0.0);
  49.         PSstroke();
  50.     }
  51.     
  52.     return self;
  53. }
  54.  
  55. - drawCirclePieMenu
  56. {
  57.     int i;
  58.     float x_center, y_center;
  59.     NXRect rect;
  60.     float angle = 360 / (float) numItems;
  61.  
  62.     [self getFrame:&rect];   /* get view size */
  63.     x_center = rect.size.width / 2.0;
  64.     y_center = rect.size.height / 2.0;
  65.     
  66.     for ( i = 0, angle = 0.0; i < numItems;
  67.           i++, angle += 360/(float) numItems )
  68.     {
  69.         if ( hitItem == i )
  70.         NXSetColor(selectedColour);
  71.     else
  72.         NXSetColor(unselectedColour);
  73.  
  74.         menu_pie(x_center, y_center, angle, angle+option1,
  75.              MM_CONVERT * option2, MM_CONVERT * (option2+option3));
  76.     PSgsave(); PSfill(); PSgrestore();
  77.     PSsetgray(0.0);
  78.     PSstroke();
  79.     }
  80.     
  81.     return self;
  82. }
  83.  
  84.  
  85. - drawCircleRectMenu
  86. {
  87.     int i;
  88.     NXRect rect;
  89.     float x_center, y_center;
  90.     float angle = 360 / (float) numItems;
  91.  
  92.     [self getFrame:&rect];   /* get view size */
  93.     x_center = rect.size.width / 2.0 - (MM_CONVERT * option1);
  94.     y_center = rect.size.height / 2.0;
  95.     
  96.     for ( i = 0, angle = 0.0; i < numItems;
  97.           i++, angle += 360/(float) numItems )
  98.     {
  99.         if ( hitItem == i )
  100.         NXSetColor(selectedColour);
  101.     else
  102.         NXSetColor(unselectedColour);
  103.         
  104.         menu_pie_rect(x_center, y_center, MM_CONVERT * option3, angle,
  105.                   MM_CONVERT * option1, MM_CONVERT * option2);
  106.         PSgsave(); PSfill(); PSgrestore();
  107.         PSsetgray(0.0);
  108.         PSstroke();
  109.     }    
  110.     
  111.     return self;
  112. }
  113.  
  114.  
  115. - drawSelf: (NXRect *) drawRects : (int) rectCount
  116. {
  117.     NXEraseRect(&bounds);
  118.  
  119.     if ( menuType == VERTICAL )
  120.         [self drawVerticalMenu];
  121.     else if ( menuType == CIRCLE_PIE )
  122.         [self drawCirclePieMenu];
  123.     else
  124.         [self drawCircleRectMenu];
  125.  
  126.     return self;
  127. }
  128.  
  129.  
  130.  
  131. - setMenuParms:(MVParms *) parms
  132. {
  133.     numItems = parms->num_items;
  134.     menuType = parms->menu_type;
  135.     option1  = parms->option1;
  136.     option2  = parms->option2;
  137.     option3  = parms->option3;
  138.     unselectedColour = parms->unselected_colour;
  139.     selectedColour   = parms->selected_colour;
  140.  
  141.     [self display];
  142.         
  143.     return self;
  144. }
  145.  
  146. - setHitItem:(int) hit_item
  147. {
  148.     hitItem = hit_item;
  149.     
  150.     return self;
  151. }
  152.  
  153. @end
  154.